package com.baize.baizeapp.test.sku

import android.content.Context
import android.util.AttributeSet
import android.view.View
import com.google.android.flexbox.FlexboxLayout

class HSFlexBoxLayout @JvmOverloads constructor(
        context: Context,
        attrs: AttributeSet,
        defStyleAttr: Int = 0
) : FlexboxLayout(context, attrs, defStyleAttr) {

    fun setAdapter(flexBoxAdapter: FlexBoxAdapter?) {
        removeAllViews()
        val itemCount = flexBoxAdapter?.getItemCount() ?: 0
        if (itemCount != 0) {
            for (i in 0 until itemCount) {
                val view = flexBoxAdapter?.getView(i)
                addView(view)
            }
            requestLayout()
        }
    }
}

interface FlexBoxAdapter {
    fun getItemCount(): Int
    fun getView(position: Int): View
}

